home *** CD-ROM | disk | FTP | other *** search
- #import "FGWindow.h"
- #import <appkit/NXImage.h>
- #import <appkit/NXBitmapImageRep.h>
- #import <dpsclient/wraps.h>
- #import <dpsclient/psops.h>
- #import "Nutation.h"
- #import <math.h>
- #define NXSetWindowLevel _NXSetWindowLevel
-
- // this window buffers the foreground (i.e. the targetGlyph) image
- // of a GlyphView. This image is kept in an offscreen window
- // called "anImage", which is initially painted transparent.
- // All drawing is directed at this offscreen window, and all
- // compositing comes from it.
-
- @implementation FGWindow: BGWindow
- { id anImage ;
- }
-
- - erase: (NXRect *) aRect ;
- { // erase (to transparent white) aRect within my image
- [anImage lockFocus] ;
- PSgsave() ;
- // PScompositerect(aRect->origin.x, aRect->origin.y,
- // aRect->size.width,aRect->size.height,NX_CLEAR) ;
- PSsetgray(1.0) ;
- PSsetalpha(0.0) ;
- NXRectFill(aRect) ;
- PSgrestore() ;
- [anImage unlockFocus] ;
- return self ;
- }
-
- - erase ;
- { // erase my image
- NXRect aRect = frame ;
- aRect.origin.x = aRect.origin.y = 0.0 ;
- return [self erase: &aRect] ;
- }
-
- - composite: (int) op fromRect: (const NXRect *) aRect toPoint: (const NXPoint *) aPnt ;
- { // actually composite from anImage
- NXRect bRect ;
- NXPoint bPnt ;
- bPnt.x = rint(aPnt->x) ;
- bPnt.y = rint(aPnt->y) ;
- bRect.size = aRect->size ;
- bRect.origin.x = rint(aRect->origin.x) ;
- bRect.origin.y = rint(aRect->origin.y) ;
- [anImage composite:op fromRect: &bRect toPoint: &bPnt] ;
- return self ;
- }
-
- - composite: (int) op toPoint: (const NXPoint *) aPnt ;
- { // actually composite from anImage
- NXRect aRect ;
- aRect.origin.x = aRect.origin.y = 0.0 ;
- [anImage getSize: &aRect.size] ;
- return [self composite: op fromRect: &aRect toPoint: aPnt] ;
- }
-
- - composite: (int) op ;
- { // actually composite from anImage
- NXPoint zeroPoint = {0.0,0.0} ;
- return [anImage composite:op toPoint: &zeroPoint] ;
- }
-
- - flushWindow ;
- { // composite anImage over ourselves
- NXPoint aPnt = {0.0,0.0} ;
- [contentView lockFocus] ;
- [anImage composite: NX_SOVER toPoint: &aPnt] ;
- [contentView unlockFocus] ;
- return self ;
- }
-
- - frame: (NXRect *) aFrame ;
- { // this is the "designated" initializer method
- // Frist, make the window which will be seen on-screen
- // when a Glyph is dragged off of its GlyphView
- [super frame: aFrame] ;
- // make an offscreen window to buffer the image
- anImage = [[NXImage alloc] initSize: &aFrame->size] ;
- // paint anImage transparent
- [self erase] ;
- return self ;
- }
-
- - free ;
- { [anImage free] ;
- return [super free] ;
- }
-
- - highLight: (NXRect *) aRect ;
- { // "highlight" aRect in my image. This is a toggle:
- // call it again to "unhighlight" it.
- [anImage lockFocus] ;
- NXHighlightRect(aRect) ;
- [anImage unlockFocus] ;
- return self ;
- }
-
- - highLight ;
- { // "highlight" my image. This is a toggle:
- // call it again to "unhighlight" it.
- NXRect aRect = frame ;
- aRect.origin.x = aRect.origin.y = 0.0 ;
- return [self highLight: &aRect] ;
- [anImage unlockFocus] ;
- return self ;
- }
-
- - image ;
- { return anImage ;
- }
-
- - (BOOL) lockFocus ;
- { // we actually lock focus on anImage
- return [anImage lockFocus] ;
- }
-
- - orderFront: sender ;
- { // before I come to the front, I paint myself
- // opaque white and composite anImage onto myself
- NXPoint zeroPoint = {0.0,0.0} ;
- [contentView lockFocus] ;
- PSsetgray(1.0) ;
- PSrectfill(0.0,0.0,frame.size.width,frame.size.height) ;
- [anImage composite: NX_SOVER toPoint: &zeroPoint] ;
- [contentView unlockFocus] ;
- PSsetgray(0.0) ;
- return [super orderFront: sender] ;
- }
-
- - sizeWindow:(NXCoord)width :(NXCoord)height ;
- { // for a Window...[anImage sizeWindow: width :height] ;
- NXSize aSize ;
- aSize.width = width ; aSize.height = height ;
- [anImage setSize: &aSize] ;
- return [super sizeWindow: width :height] ;
- }
-
- - unlockFocus ;
- { // we actually lock focus on anImage
- return [anImage unlockFocus] ;
- }
-
- - helpMe ;
- { NXStream *aStream ;
- aStream = NXOpenMemory(NULL,0, NX_READWRITE);
- if(aStream != NULL)
- { [anImage writeTIFF: aStream] ;
- NXSaveToFile(aStream, "/tmp/helpMe.tiff") ;
- NXCloseMemory(aStream,NX_FREEBUFFER);
- }
- else
- [Nu printf: "can't map file\n"] ;
- }
-
- @end